package com.zhang.authoritycenter.common.aspect;

import com.zhang.infrastructure.aspect.CustomCacheEvict;
import com.zhang.redis.util.RedisManager;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * description
 *
 * @author zhangFanJun
 * @date 2024-01-16 19:36
 **/
@Slf4j
@Aspect
@Component
public class CustomCacheEvictAop {

    @Resource
    private RedisManager<String> redisManager;

    @AfterReturning("@annotation(customCacheEvict)")
    public void evictCache(CustomCacheEvict customCacheEvict) {
        String key = customCacheEvict.value();
        if(ObjectUtils.isEmpty(key)){
            return;
        }
        redisManager.template().delete(key);
        log.info("删除key：{}",key);
    }
}
